package com.tedu.jsd2407_ivos_fzj.dictoption.controller;

import com.tedu.jsd2407_ivos_fzj.base.response.JsonResult;
import com.tedu.jsd2407_ivos_fzj.dictoption.pojo.dto.DictOptionParam;
import com.tedu.jsd2407_ivos_fzj.dictoption.pojo.dto.DictOptionQuery;
import com.tedu.jsd2407_ivos_fzj.dictoption.pojo.vo.DictOptionVO;
import com.tedu.jsd2407_ivos_fzj.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/v1/dictOption")
@RestController
@Slf4j
public class DictOptionController {

    @Autowired
    private DictOptionService dictOptionService;//注入的是接口

    @GetMapping("/select")
    public JsonResult select(DictOptionQuery dictOptionQuery){
        log.debug("字典项查询，参数：{}",dictOptionQuery);
        List<DictOptionVO> dictOptionVOList = dictOptionService.select(dictOptionQuery);
        return JsonResult.ok(dictOptionVOList);
    }
    @PostMapping("/save")
    public JsonResult save(DictOptionParam dictOptionParam){
        log.debug("保存字典项信息，参数：{}",dictOptionParam);
        dictOptionService.save(dictOptionParam);
        return JsonResult.ok();
    }
    @PostMapping("/deleteById/{id}")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("根据字典项id删除，参数：{}",id);
        dictOptionService.deleteById(id);
        return JsonResult.ok();
    }
    /**
     * 根据字典code查询该字典下所有的字典项
     */
    @GetMapping("/select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("根据字典code查询该字典下的所有字典项，参数：{}",code);
        List<DictOptionVO> dictOptionVOList = dictOptionService.selectByCode(code);
        return JsonResult.ok(dictOptionVOList);
    }

}
